<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Reload</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
</head>
<body>

<h1>Reload</h1>

<p>Replaces the currently running instance of the script with a new one.</p>

<pre class="Syntax">Reload</pre>
<p>This command is useful for scripts that are frequently changed. By assigning a hotkey to this command, you can easily restart the script after saving your changes in an editor.</p>
<p>Any <a href="../Scripts.htm#cmd">command-line parameters</a> passed to the original script are not passed to the new instance. To pass such parameters, do not use Reload. Instead, use <a href="Run.htm">Run</a> in conjunction with <a href="../Variables.htm#AhkPath">A_AhkPath</a> and <a href="../Variables.htm#ScriptFullPath">A_ScriptFullPath</a> (and <a href="../Variables.htm#IsCompiled">A_IsCompiled</a> if the script is ever used in compiled form). Also, include the string <code>/restart</code> as the first parameter (i.e. after the name of the executable), which tells the program to use the same behavior as Reload. See also: <a href="../Scripts.htm#cmd">command line switches and syntax</a>.</p>
<p>When the script restarts, it is launched in its original working directory (the one that was in effect when it was first launched). In other words, <a href="SetWorkingDir.htm">SetWorkingDir</a> will not change the working directory that will be used for the new instance.</p>
<p>If the script cannot be reloaded -- perhaps because it has a syntax error -- the original instance of the script will continue running. Therefore, the reload command should be followed by whatever actions you want taken in the event of a failure (such as a <a href="Return.htm">return</a> to exit the current subroutine). To have the original instance detect the failure, follow this example:</p>
<pre>Reload
Sleep 1000 <em>; If successful, the reload will close this instance during the Sleep, so the line below will never be reached.</em>
MsgBox, 4,, The script could not be reloaded. Would you like to open it for editing?
IfMsgBox, Yes, Edit
return</pre>
<h3>Related</h3>
<p><a href="Edit.htm">Edit</a></p>
<h3>Example</h3>
<pre class="NoIndent">^!r::Reload  <em>; Assign Ctrl-Alt-R as a hotkey to restart the script.</em></pre>

</body>
</html>
